package com.da.javatest.leetCode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenlida
 * @date 2019/1/18 10:47
 * @description
 */
public class Code409 {
    public int longestPalindrome(String s) {
        int total = 0;
        final Boolean[] flag = {false};
        Map<Character, Integer> map = new HashMap<>(s.length());
        for (char c : s.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        total += map.values().stream().mapToInt(v -> {
            if (v % 2 == 0) {
                return v;
            } else {
                flag[0] = true;
                return v - 1;
            }
        }).sum();
        if (flag[0]) {
            total++;
        }
        return total;
    }
}
